target_num = 24

def dfs_solver(input_list):
    path_list = []
    search(input_list,path_list)

class Node():
    def __init__(self,operator,left_operand,right_operand):
        self.operator = operator
        self.left_operand = left_operand
        self.right_operand = right_operand


def print_path(path_list):
    print("一个可行解如下")
    for node in path_list:
        if node.operator == "+":
            result = node.left_operand + node.right_operand
            row_data = "{}{}{}={}".format(str(node.left_operand),node.operator,str(node.right_operand), str(result))
            print(row_data)
        if node.operator == "-":
            result = node.left_operand - node.right_operand
            row_data = "{}{}{}={}".format(str(node.left_operand), node.operator, str(node.right_operand), str(result))
            print(row_data)
        if node.operator == "*":
            result = node.left_operand * node.right_operand
            row_data = "{}{}{}={}".format(str(node.left_operand),node.operator,str(node.right_operand), str(result))
            print(row_data)
        if node.operator == "/":
            result = node.left_operand // node.right_operand
            row_data = "{}{}{}={}".format(str(node.left_operand), node.operator, str(node.right_operand), str(result))
            print(row_data)
    print("\n")
def search(input_list,path_list):
    #print(input_list)
    if len(input_list) == 0:
        return False;
    if len(input_list) == 1:
        if input_list[0] == target_num:
            print_path(path_list)
            return True
        else:
            return False
    for left_index,left_operand in enumerate(input_list):
        for right_index,right_operand in enumerate(input_list):
            if left_index == right_index:
                continue;

            tmp_list = [];
            for tmp_index, tmp_num in enumerate(input_list):
                if tmp_index == left_index:
                    continue;
                if tmp_index == right_index:
                    continue;
                tmp_list.append(tmp_num)



            for k in [1,2,3,4]:
                if k == 1:
                    #print("add")
                    tmp_list_1 = []
                    tmp_list_1.extend(tmp_list)
                    next_num = left_operand + right_operand
                    tmp_list_1.append(next_num)
                    tmp_node = Node("+", left_operand, right_operand)
                    path_list.append(tmp_node)
                    tmp_ret = search(tmp_list_1,path_list)
                    path_list.pop();
                    if tmp_ret:
                        return True;

                if k == 2:
                    #print("sub")
                    tmp_list_2 = []
                    tmp_list_2.extend(tmp_list)
                    next_num = left_operand - right_operand
                    tmp_list_2.append(next_num)
                    tmp_node = Node("-", left_operand, right_operand)
                    path_list.append(tmp_node)
                    tmp_ret = search(tmp_list_2, path_list)
                    path_list.pop();
                    if tmp_ret:
                        return True;
                if k == 3:
                    #print("mul")
                    tmp_list_3 = []
                    tmp_list_3.extend(tmp_list)
                    next_num = left_operand * right_operand
                    tmp_list_3.append(next_num)
                    tmp_node = Node("*", left_operand, right_operand)
                    path_list.append(tmp_node)
                    tmp_ret = search(tmp_list_3, path_list)
                    path_list.pop();
                    if tmp_ret:
                        return True;
                if k == 4:
                    #print("divide")
                    tmp_list_4 = []
                    tmp_list_4.extend(tmp_list)
                    if right_operand == 0:
                        continue
                    next_num = left_operand // right_operand
                    tmp_list_4.append(next_num)
                    tmp_node = Node("/", left_operand, right_operand)
                    path_list.append(tmp_node)
                    tmp_ret = search(tmp_list_4, path_list)
                    path_list.pop();
                    if tmp_ret:
                        return True;

    return False;